﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HaGisPack
{


    /// <summary>
    /// 暂时只提供一层复合的能力，多出的话，会发生错误
    /// </summary>
    [Serializable ]
   public  class FCompoundLayer:FLayer 
    {
       public FCompoundLayer(string id):base(id)
       {

           m_Childs = new Dictionary<string, FLayer>();


           this.m_LayerType = FLayerType.CompoundLayer;

       }

       //用于存放一级子元素
       Dictionary<string, FLayer> m_Childs;

       /// <summary>
       /// 所有的子元素
       /// </summary>
       public Dictionary<string, FLayer> Childs
       {
           get { return m_Childs; }
           //set { m_Childs = value; }
       }


       protected  override void BuildLayer()
       {
           base.BuildLayer();

           //子元素构建
           foreach (FLayer  item in m_Childs .Values )
           {
               item.ParentManger = this.m_ParenLManager;

               item.BuildEntity ();
               
           }


       }


       public void AddChild(FLayer layer)
       {

           m_Childs.Add(layer.Id, layer);
           if (BRunning )
           {
               layer.ParentManger = this.m_ParenLManager;

               layer.BuildEntity();

               this.m_ParenLManager.LayerSys.declareLayerChanged();
           }
 
       }

       public FLayer GetChild(string lname)
       {
           if (m_Childs.ContainsKey(lname))
           {
               return m_Childs[lname];
           }
           else
           {
               return null;
           }
       }


       public bool IsChildExist(string lname)
       {
           if (m_Childs.ContainsKey(lname))
           {
               return true;
           }
           else
           {
               return false;
           }
       }


       public override void CloseLayer()
       {
           base.CloseLayer();
           foreach (FLayer lay in this.m_Childs.Values)
           {
               lay.CloseLayer();
           }
       }

    }
}
